local skel = fk.CreateSkill {
  name = "emo__gongnong",
  tags = {Skill.Compulsory},
}

skel:addEffect("viewas", {
  pattern = ".|.|.|.|.|basic",
  prompt = "#emo__gongnong",
  derived_piles = "emo__gongnong_pile",
  interaction = function(self, player)
    local all_choices = {}
    for _, id in ipairs(player:getPile("emo__gongnong_pile")) do
      table.insertIfNeed(all_choices, Fk:getCardById(id, true).name)
    end
    local choices = player:getViewAsCardNames(skel.name, all_choices)
    if #choices > 0 then
      return UI.CardNameBox { choices = choices, all_choices = all_choices }
    end
  end,
  card_filter = Util.FalseFunc,
  view_as = function (self, player, cards)
    local name = self.interaction.data
    if not name then return nil end
    local c = Fk:cloneCard(name)
    c.skillName = skel.name
    return c
  end,
  before_use = function(self, player, use)
    local room = player.room
    local cards = table.filter(player:getPile("emo__gongnong_pile"), function (id)
      return Fk:getCardById(id, true).trueName == use.card.trueName
    end)
    if #cards == 0 then return skel.name end
    room:recastCard(cards, player, skel.name)
  end,
  enabled_at_play = function(self, player)
    return #player:getPile("emo__gongnong_pile") > 0
  end,
  enabled_at_response = function (self, player, response)
    if Fk.currentResponsePattern then
      return table.find(player:getPile("emo__gongnong_pile"), function (id)
        return Exppattern:Parse(Fk.currentResponsePattern):matchExp(Fk:getCardById(id, true).trueName)
      end)
    end
  end,
})

local can_trigger = function(self, event, target, player, data)
  if player:hasSkill(skel.name) and player.phase ~= Player.NotActive and data.card.type == Card.TypeBasic then
    return table.find(Card:getIdList(data.card), function (id)
      return Fk:getCardById(id, true).type == Card.TypeBasic
    end)
  end
end

local on_use = function(self, event, target, player, data)
  local cards = table.filter(Card:getIdList(data.card), function (id)
    return Fk:getCardById(id, true).type == Card.TypeBasic
  end)
  player:addToPile("emo__gongnong_pile", cards, true, "emo__gongnong")
end

skel:addEffect(fk.CardUseFinished, {
  anim_type = "drawcard",
  can_trigger = can_trigger,
  on_use = on_use,
})

skel:addEffect(fk.CardRespondFinished, {
  anim_type = "drawcard",
  can_trigger = can_trigger,
  on_use = on_use,
})

Fk:loadTranslationTable{
  ["emo__gongnong"] = "躬农",
  [":emo__gongnong"] = "锁定技，你的回合内有基本牌结算后，你将此牌置于武将牌上；你可以重铸武将牌上的所有同名牌，视为使用或打出之。",

  ["emo__gongnong_pile"] = "农",
  ["#emo__gongnong"] = "躬农：选择你要视为使用打出的牌，重铸所有“躬农”牌视为使用打出之",
}


return skel
